package pl.poznan.put.cs.idss.students.coolring.ui.components;

import java.awt.Color;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.border.EmptyBorder;

public class ImageButton extends JButton implements MouseListener {

	private static final long serialVersionUID = -6979143980976231601L;

	private ImageIcon imageIcon = null;
	private ImageIcon hoverImageIcon = null;

	private int left = 0;
	private int top = 0;

	public ImageButton() {
		super();
		addMouseListener(this);
        setContentAreaFilled(false);
		setBackground(new Color(0, 0, 0, 0));
		setEnabled(true);
		setBorder(new EmptyBorder(0, 0, 0, 0));
		setBorderPainted(false);
	}

	public void setImage(Image image) {
		imageIcon = new ImageIcon(image);
		setBounds(left, top, (int) image.getWidth(this),
				(int) image.getHeight(this));
		setIcon(imageIcon);
	}

	public void setLeftTop(int left, int top) {
		this.left = left;
		this.top = top;
	}

	public void setHoverImage(Image image) {
		hoverImageIcon = new ImageIcon(image);
	}

	public void mouseClicked(MouseEvent arg0) {
		setOpaque(false);
		setContentAreaFilled(false);
		setBackground(new Color(0, 0, 0, 0));
	}

	public void mouseEntered(MouseEvent arg0) {
		if (hoverImageIcon != null) {
			setIcon(hoverImageIcon);
		}
	}

	public void mouseExited(MouseEvent arg0) {
		if (imageIcon != null) {
			setIcon(imageIcon);
		}
	}

	public void mousePressed(MouseEvent arg0) {
	}

	public void mouseReleased(MouseEvent arg0) {
	}

}
